cd C:\Users\a0910846\Dropbox\Storting

***********************************************************************
************************NOP PRE-REFORM ********************************
***********************************************************************

use dta/parties_competing, clear /* THIS FILE IS CREATED IN SMD_Descriptives_Party.do in Storting/do */

keep if round==1 /* only interested in parties running in the first round */
drop if party=="spr"  /* THESE ARE SMALL NUMBER OF VOTES FOR VARIOUS CANDIDATES */

collapse (sum) running, by(party valgkrets year)  /* this dataset shows the number of cand. running in first round in each district for each party */

gen running2=running>0   /* dummy =1 if any candidate is running from the party */

drop running
rename running2 running
reshape wide running, i(valgkrets year) j(party) string

*gen NoC=runninga+runningfv+runningh+runningh_fv+runningkir+runningl+runningoth+runnings+runningt+runningv+runningv_a
gen NoP=runninga+runningfv+runningh+runningh_fv+runningkir+runningl+runningoth+runnings+runningt+runningv+runningv_a

foreach v in running {
rename `v'a `v'RF   
rename `v'fv `v'FV
rename `v'h `v'H
rename `v'h_fv `v'H_FV
rename `v'kir `v'KIR
rename `v'l `v'SP    
rename `v'oth `v'OTH
rename `v's `v'DNA    
rename `v't `v'T
rename `v'v `v'V
rename `v'v_a `v'V_RF
}


/* From 1921 pdf */  /*
F�lgende partier
deltok: 
� H�ire (H.) og Det frisindede venstre (F. V.)- Disse partier var i de fleste valgdistrikter sammensluttet og betegnes H. og F. V. 
� Norsk landmandsforbnnd = L. Partiet har efter valget forandret navn til Norges bondelag. 
� Venstre = V. 
� Det radikale folkeparti = K. F. Dette er det tidligere arbeiderdemokratiske parti 
� Norges socialdemokratiske arbeiderparti = S. 
� Det norske arbeiderparti = A. De to siste partier utgj�r tilsammen det tidligere samlede socialdemokratiske parti.
*/

rename valgkrets SMD_district
sum running*
sort year SMD_district
save ../PRTurnout/dta/NoP/NoP_pre.dta, replace  /* NoP from the pre-reform period */


***********************************************************************
************************NOP POST-REFORM *******************************
***********************************************************************

use dta\Storting1921, clear 
foreach party in DNA NSA RF V SP H_FV OTH{
gen running`party'=votes`party'>0
}
gen NoP=runningDNA+runningNSA+runningRF+runningV+runningSP+runningH_FV+runningOTH
rename valgkrets PR_district 
keep year NoP PR_district running*
sum NoP
sort year PR_district
save ../PRTurnout/dta/NoP/NoP1921.dta, replace

***********************************************************************

use dta\Storting1924, clear 
foreach party in NKP DNA NSA RF V SP FV H_FV OTH{
gen running`party'=votes`party'>0
}
gen NoP=runningNKP+runningDNA+runningNSA+runningRF+runningV+runningSP+runningFV+runningH_FV+runningOTH
rename valgkrets PR_district
keep year NoP PR_district running*
sum NoP
sort year PR_district
save ../PRTurnout/dta/NoP/NoP1924.dta, replace

***********************************************************************

foreach year in 1927 1930 {
use dta\Storting`year', clear 
foreach party in NKP DNA RF V SP FV H_FV OTH{
gen running`party'=votes`party'>0
}
gen NoP=runningNKP+runningDNA+runningRF+runningV+runningSP+runningFV+runningH_FV+runningOTH
rename valgkrets PR_district
keep year NoP PR_district running*
sum NoP
sort year PR_district
save ../PRTurnout/dta/NoP/NoP`year'.dta, replace
}


***********************************************************************
foreach year in 1933 1936 {
use dta\Storting`year', clear 
foreach party in NKP DNA RF V SP MORE SAM FV H_FV NS KRF OTH {
gen running`party'=votes`party'>0
}
gen NoP=runningNKP+runningDNA+runningRF+runningV+runningSP+runningMORE+runningSAM+runningFV+runningH_FV+runningNS+runningKRF+runningOTH
rename valgkrets PR_district
keep year NoP PR_district running*
sum NoP
sort year PR_district
save ../PRTurnout/dta/NoP/NoP`year'.dta, replace
}

cd C:\Users\a0910846\Dropbox\PRTurnout
